package main

import (
	"fmt"
	"time"
)

func main() {
	// 1. 使用 time 包预定义的常量
	var d1 time.Duration = time.Second
	var d2 time.Duration = time.Millisecond
	var d3 time.Duration = time.Microsecond
	var d4 time.Duration = time.Nanosecond
	var d5 time.Duration = time.Minute
	var d6 time.Duration = time.Hour

	fmt.Println(d1, d2, d3, d4, d5, d6)

	// 2. 通过乘法创建
	tenSeconds := 10 * time.Second
	twoHours := 2 * time.Hour
	halfSecond := 500 * time.Millisecond

	fmt.Println(tenSeconds, twoHours, halfSecond)

	// 3. 使用 time.ParseDuration (字符串解析)
	d, err := time.ParseDuration("1h30m15s")
	if err != nil {
		panic(err)
	}
	fmt.Println("解析的时长:", d) // 1h30m15s
}
